Skip to content

Conversation

lukasz-antoniak
Copy link
Member

Fix CASSANDRA-19931.

Example OR operator:

assertThat(
        selectFrom("foo")
            .all()
            .where(Relation.column("k").isEqualTo(literal(1)))
            .and()
            .where(Relation.column("l").isEqualTo(literal(2)))
            .or()
            .where(Relation.column("m").isEqualTo(literal(3)))
            .orderBy("c1", ASC)
            .orderBy("c2", DESC))
    .hasCql("SELECT * FROM foo WHERE k=1 AND l=2 OR m=3 ORDER BY c1 ASC,c2 DESC");

Example sub-condition:

assertThat(
        selectFrom("foo")
            .all()
            .where(Relation.column("k").isEqualTo(literal(1)))
            .and()
            .where(
                subCondition()
                    .where(Relation.column("l").isEqualTo(literal(2)))
                    .or()
                    .where(Relation.column("m").isEqualTo(literal(3))))
            .orderBy("c1", ASC)
            .orderBy("c2", DESC))
    .hasCql("SELECT * FROM foo WHERE k=1 AND (l=2 OR m=3) ORDER BY c1 ASC,c2 DESC");

.where(Relation.column("m").isEqualTo(literal(3))))
.orderBy("c1", ASC)
.orderBy("c2", DESC))
.hasCql("SELECT * FROM foo WHERE k=1 AND (l=2 OR m=3) ORDER BY c1 ASC,c2 DESC");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, this a 'recursive' building.
So we can have

SELECT * FROM foo WHERE k=1 AND (l=2 OR m=3 OR (q=4 AND p=5 )) ORDER BY c1 ASC,c2 DESC"

Or other complex nested logical query?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are correct. I have made one of the queries more complex.

.orderBy("c1", ASC)
.orderBy("c2", DESC))
.hasCql("SELECT * FROM foo WHERE k=1 AND (l=2 OR m=3) ORDER BY c1 ASC,c2 DESC");
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible we can add some more complex logical query in tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced last test to be more complex. Above tests also verify backward-compatibility of current default AND operator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants